# Copyright 2007 Boris Dusek
#
# This file is part of grapy.
#
# Grapy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Grapy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Grapy.  If not, see <http://www.gnu.org/licenses/>.

#!/usr/bin/env python

import sys

from grapy.AdjListGraph import AdjListGraph
from grapy.Graph import graph_option_parser

if __name__ == "__main__":
    parser = graph_option_parser()
    (options,args) = parser.parse_args()
    f = open (args[0], 'r')
    g = AdjListGraph (options.multi, options.directed)
    g.init_from_stream (f)
    f.close ()

    for u in g.vertices():
        distances = dict([(u,g.BFS(u)[0]) for u in g.vertices()])

    for u in g.vertices():
        max = -1
        for v, d in distances[u].iteritems():
            if d > max:
                max = d
                v_max = [v]
            elif d == max:
                v_max.append(v)
        for v in v_max:
            print max(distances[v])
